package org.shindou09.easytagforpage.view;

import org.shindou09.easytagforpage.view.impl.FreeMarkerPageViewImpl;
import org.shindou09.easytagforpage.view.impl.JspPageViewImpl;

public class PageViewFactory {

	private PageViewFactory(){}
	
	private static PageView pageView;
	
	public static PageView getPageView(String pv){
		if(pageView==null){
			if(pv.equals("ftl")){
				try {
					Class.forName("freemarker.template.Configuration");
					pageView=new FreeMarkerPageViewImpl();
				} catch (ClassNotFoundException e) {
					// TODO: handle exception
					pageView=new JspPageViewImpl();
				}
				return pageView;
			}else if(pv.equals("jsp")){
				pageView=new JspPageViewImpl();
			}else{
				try {
					pageView=(PageView) Class.forName(pv).newInstance();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return pageView;
	}
}
